<?php
header('Content-Type: text/xml');
?> 
<?php 

include("../db/opendb.php");

include("functions.php");

/*$query1 = "select AVG(Price_Per_SQFT) as avg from Game_Data where City = 'San Francisco' and Property_Type = 'RESI' and Selling_Date >= DATE_SUB(now(), INTERVAL 3 month);";
$result1 = mysql_query($query1) or die ("SQL Error".mysql_error());
$row1 = mysql_fetch_assoc($result1);*/
//echo $row1['avg'];

$query = "select count(g.Listing_Number) as total, avg(Current_Price) as avg_price, p.Name from Game_Data g inner join Game_Districts d on d.District_Number = g.District inner join Game_District_Parents p on p.ID = d.Parent where Status in ('A','ACTIVE','C') group by p.Name";

$result = mysql_query($query) or die ("SQL Error".mysql_error());

$xml = "<areas>";

while ($row = mysql_fetch_assoc($result))
{
	$xml .= "<area>";
	$xml .= "<name><![CDATA[".$row['Name']."]]></name>";
	$xml .= "<total><![CDATA[".$row['total']."]]></total>";
	$xml .= "<avg_price><![CDATA[".$row['avg_price']."]]></avg_price>";
	$xml .= "</area>";
}
$xml .= "</areas>";

echo $xml;

?>
